package org.zebra.message;

import lombok.extern.slf4j.Slf4j;
import org.dromara.sms4j.comm.exception.SmsBlendException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.zebra.common.core.Result;
import org.zebra.common.exception.StatusCode;

import javax.servlet.http.HttpServletRequest;

/**
 * SMS异常处理器
 *
 * @author zhanghongbin
 */
@Slf4j
@RestControllerAdvice
public class SmsExceptionAdvice {

    /**
     * sms异常
     */
    @ExceptionHandler(SmsBlendException.class)
    public Result<?> handleSmsBlendException(SmsBlendException e, HttpServletRequest request) {
        String requestURI = request.getRequestURI();
        log.error("请求地址'{}',发生sms短信异常.", requestURI, e);
        return new Result()
                .toBuilder()
                        .code(StatusCode.SMS_FAILED.getCode())
                        .msg(StatusCode.SMS_FAILED.getMsg())
                        .build();
    }
}
